home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 58606 / 58606.xpi / chrome / translator.jar / content / popup.js < prev    next >
Text File  |  2010-02-07  |  4KB  |  207 lines

  1.  
  2. (function(namespace, $)
  3. {
  4.     namespace.Popup = function(doc)
  5.     {
  6.         this.doc = doc;
  7.     };
  8.     
  9.     namespace.Popup.prototype = {
  10.         initialized: false,
  11.         doc: null,
  12.         el: null,
  13.         elMessage: null,
  14.         elNotice: null,
  15.         elTextarea: null,
  16.         css: {},
  17.         message: '',
  18.         notice: '',
  19.         visible: false,
  20.         
  21.         init: function()
  22.         {
  23.             if(this.initialized) return;
  24.             
  25.             // create popup element
  26.             this.createPopupElement();
  27.             
  28.             this.initialized = true;
  29.         },
  30.         
  31.         uninit: function()
  32.         {
  33.             this.reset();
  34.             
  35.             this.el.remove();
  36.             this.el = null;
  37.             this.elMessage = null;
  38.             this.elNotice = null;
  39.             this.elTextarea = null;
  40.             this.css = {};
  41.             this.message = '';
  42.             this.notice = '';
  43.             this.visible = false;
  44.             this.initialized = false;
  45.         },
  46.         
  47.         createPopupElement: function()
  48.         {
  49.             this.el = $('<div class="translator-popup"></div>', this.doc);
  50.             this.elMessage = $('<div></div>', this.doc).appendTo(this.el);
  51.             this.elNotice = $('<div></div>', this.doc).appendTo(this.el);
  52.             this.elTextarea = $('<textarea></textarea>', this.doc).appendTo(this.el).hide();
  53.             
  54.             // style it
  55.             this.el.css({
  56.                 background: '#D9C6B6',
  57.                 border: '3px #784F2B ridge',
  58.                 bottom: 'auto',
  59.                 display: 'none',
  60.                 height: 'auto',
  61.                 left: 0,
  62.                 margin: 0,
  63.                 maxWidth: '500px',
  64.                 maxWidth: '350px',
  65.                 overflow: 'auto',
  66.                 padding: 0,
  67.                 position: 'fixed',
  68.                 right: 'auto',
  69.                 textAlign: 'left',
  70.                 top: 0,
  71.                 width: 'auto',
  72.                 zIndex: 9999999999
  73.             });
  74.             
  75.             this.elMessage.css({
  76.                 color: '#111',
  77.                 fontFamily: 'Helvetica, Arial, sans-serif',
  78.                 fontSize: '14px',
  79.                 padding: '5px 7px'
  80.             });
  81.             
  82.             this.elNotice.css({
  83.                 color: '#9D0505',
  84.                 fontFamily: 'Helvetica, Arial, sans-serif',
  85.                 fontSize: '14px',
  86.                 fontStyle: 'italic',
  87.                 padding: '5px 7px'
  88.             });
  89.             
  90.             $('body', this.doc).append(this.el);
  91.         },
  92.         
  93.         reloadCss: function()
  94.         {
  95.             this.el.css({
  96.                 bottom: (this.css.x != undefined ? 'auto' : 0),
  97.                 left: (this.css.x != undefined ? this.css.x : 'auto'),
  98.                 maxHeight: (Math.min(this.doc.defaultView.innerHeight, 500) - 6/*border*/ - 20/*possible scrollbar*/) + 'px',
  99.                 maxWidth: (Math.min(this.doc.defaultView.innerWidth, 350) - 6/*border*/ - 20/*possible scrollbar*/) + 'px',
  100.                 right: (this.css.y != undefined ? 'auto' : 0),
  101.                 top: (this.css.y != undefined ? this.css.y : 'auto')
  102.             });
  103.         },
  104.         
  105.         setMessage: function(message)
  106.         {
  107.             if(!this.initialized) {
  108.                 this.init();
  109.             }
  110.             
  111.             // put message in textarea to handle all special chars
  112.             this.elTextarea[0].innerHTML = message;
  113.             
  114.             // assign to message
  115.             this.message = this.elTextarea.val();
  116.             
  117.             // update message element
  118.             this.elMessage.text(this.message);
  119.         },
  120.         
  121.         setNotice: function(notice)
  122.         {
  123.             if(!this.initialized) {
  124.                 this.init();
  125.             }
  126.             
  127.             // assign to notice
  128.             this.notice = notice;
  129.             
  130.             // update notice element
  131.             this.elNotice.text(this.notice);
  132.         },
  133.         
  134.         showMessage: function()
  135.         {
  136.             if(!this.initialized) {
  137.                 this.init();
  138.             }
  139.             
  140.             // style for message
  141.             this.el.css({
  142.                 borderColor: '#784F2B'
  143.             });
  144.             
  145.             // call standard show function
  146.             this.show();
  147.         },
  148.         
  149.         showError: function()
  150.         {
  151.             if(!this.initialized) {
  152.                 this.init();
  153.             }
  154.             
  155.             // style for error
  156.             this.el.css({
  157.                 borderColor: '#C31919'
  158.             });
  159.             
  160.             // call standard show function
  161.             this.show();
  162.         },
  163.         
  164.         show: function()
  165.         {
  166.             if(!this.initialized) {
  167.                 this.init();
  168.             }
  169.             
  170.             if(!this.el) return;
  171.             
  172.             this.reloadCss();
  173.             
  174.             // show/hide translation element
  175.             this.elMessage[this.message.length ? 'show' : 'hide']();
  176.             
  177.             // show/hide notice element
  178.             this.elNotice[this.notice.length ? 'show' : 'hide']();
  179.             
  180.             if(!this.visible) {
  181.                 this.visible = true;
  182.                 
  183.                 this.el.show(250);
  184.             }
  185.         },
  186.         
  187.         hide: function()
  188.         {
  189.             if(!this.el) return;
  190.             
  191.             this.el.hide(100);
  192.             
  193.             this.visible = false;
  194.         },
  195.         
  196.         setPosition: function(x, y)
  197.         {
  198.             this.css.x = x + 5;
  199.             this.css.y = y + 5;
  200.         },
  201.         
  202.         resetPosition: function()
  203.         {
  204.             this.css = {};
  205.         }
  206.     };
  207. })(com.igorgladkov.translator, translatorJQuery);